<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { auditApi } from '@/api/controller';
  import { parseTime } from '@/utils/index';
  import { Toastloading } from '@/utils/public';
  import Pagination from "@/components/Pagination/index.vue";
  import xmImage from '@/components/xmImage/index.vue';
  import solveForm from './solveForm.vue';
  import forbidUserForm from '@/views/user/userList/components/forbidUserForm.vue';
  const solveFormRef = ref(),
  forbidUserFormRef = ref()
  const action = reactive({
    total:0,
    list:[] as any[],
  })
  const listQuery = reactive({
    page:1,
    limit:20,
    uuid: '',
    dispose: 0,
    sort: 'asc'
  })
  const handleSerach = ()=>{
    listQuery.page = 1
    getList()
  }
  const handleForm = (row:any = {})=>{
    solveFormRef.value.openDialog(row)
  }
  const handleSealing = (row:any = {})=>{
    forbidUserFormRef.value.openDialog({
      operate_type:1,
      ...row
    })
  }
  const getList = async()=> {
    const loading = Toastloading()
    const res = await auditApi.getReportRooms(listQuery)
    loading.close()
    const { data=[], total=0 } = res.data
    action.total = total
    action.list = data
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">举报人UUID：</div>
          <el-input v-model="listQuery.uuid" clearable placeholder="请输入举报人UUID"/>
        </div>
        <div class="labelItem">
          <div class="label">处理状态：</div>
          <el-select v-model="listQuery.dispose" placeholder="请选择处理状态">
            <el-option label="未处理" :value="0"/>
            <el-option label="已处理" :value="1"/>
          </el-select>
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">查询</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border
    >
      <el-table-column width="120" prop="report_user.uuid" label="举报人UUID" />
      <el-table-column min-width="100" prop="room.room_uid" label="被举报房间" />
      <el-table-column min-width="100" prop="value" label="举报类型">
        <template #default="scoped">
          <el-tag>
            {{ ['', '色情', '广告', '诈骗', '侮辱诋毁', '其他原因'][scoped.row.report_type] || scoped.row.report_type }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column min-width="100" prop="desc" label="举报截图">
        <template #default="scoped">
          <xmImage style="width: 100px;" :src="scoped.row.pics" :list="[scoped.row.pics]" />
        </template>
      </el-table-column>
      <el-table-column min-width="100" prop="describe" label="描述" />
      <el-table-column min-width="100" prop="create_timestamp" label="举报时间">
        <template #default="scoped">
          {{ parseTime(scoped.row.create_timestamp, '{y}-{m}-{d} {h}:{i}') }}
        </template>
      </el-table-column>
      <el-table-column min-width="100" prop="dispose_desc" label="处理说明" />
      <el-table-column width="160" label="操作">
        <template #default="scoped">
          <el-button type="primary" @click="handleForm(scoped.row)">处理</el-button>
          <el-button type="danger" @click="handleSealing(scoped.row)">封号</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
    <solveForm ref="solveFormRef" @update-list="getList" />
    <forbidUserForm ref="forbidUserFormRef" @update-list="getList" />
  </div>
</template>